export default {
    //商品列表
    tableData: state => state.tableData,
    //购物车的列表
    cartProducts: state => {
        return state.added.map(({ id, num }) => {
            let product = state.tableData.find(n => n.id == id)
            return {
                ...product,
                num
            }
        })
    },
    //计算总价
    totalPrice: (state, getters) => {
        let total = 0;
        getters.cartProducts.forEach(n => {
            total += n.price * n.num
        });
        return total;
    },
    //计算总数量
    totalNum: (state, getters) => {
        let total = 0;
        getters.cartProducts.forEach(n => {
            total += n.num;
        })
        return total;
    }
}